package com.mori.encrypt.spring.boot.core.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>  </p>
 *
 * @author mori
 * @since 2020/9/29 15:21
 */
@ConfigurationProperties(prefix = "encrypt")
public class EncryptConfigProperties {

	/**
	 * 响应数据加密的key
	 */
	private String encryptKey;

	/**
	 * 请求路径参数解密key
	 */
	private String paramDecryptKey;

	/**
	 * 请求数据体解密的key
	 */
	private String bodyDecryptKey;

	/**
	 * 需要对请求内容进行解密的接口URI<br>
	 * 比如：/user/list<br>
	 * 不支持@PathVariable格式的URI
	 */
	private List<String> requestDecryptUriList = new ArrayList<String>();
	/**
	 * 需要对响应内容进行加密的接口URI<br>
	 * 比如：/user/list<br>
	 * 不支持@PathVariable格式的URI
	 */
	private List<String> responseEncryptUriList = new ArrayList<String>();

	/**
	 * 过滤器拦截模式
	 */
	private String[] urlPatterns = new String[] { "/*" };

	/**
	 * 过滤器执行顺序
	 */
	private Integer order = 1;

	/**
	 * 是否启用加解密，比如api环境不进行加密解密
	 */
	private Boolean enable = true;

	/**
	 * 响应数据编码
	 */
	private String responseCharset = "UTF-8";

	private Map<String, List<String>> requestDecryptParamMap = new HashMap<>();

	public String getEncryptKey() {
		return encryptKey;
	}

	public void setEncryptKey(String encryptKey) {
		this.encryptKey = encryptKey;
	}

	public String getParamDecryptKey() {
		return paramDecryptKey;
	}

	public void setParamDecryptKey(String paramDecryptKey) {
		this.paramDecryptKey = paramDecryptKey;
	}

	public String getBodyDecryptKey() {
		return bodyDecryptKey;
	}

	public void setBodyDecryptKey(String bodyDecryptKey) {
		this.bodyDecryptKey = bodyDecryptKey;
	}

	public List<String> getRequestDecryptUriList() {
		return requestDecryptUriList;
	}

	public void setRequestDecryptUriList(List<String> requestDecryptUriList) {
		this.requestDecryptUriList = requestDecryptUriList;
	}

	public List<String> getResponseEncryptUriList() {
		return responseEncryptUriList;
	}

	public void setResponseEncryptUriList(List<String> responseEncryptUriList) {
		this.responseEncryptUriList = responseEncryptUriList;
	}

	public String[] getUrlPatterns() {
		return urlPatterns;
	}

	public void setUrlPatterns(String[] urlPatterns) {
		this.urlPatterns = urlPatterns;
	}

	public Integer getOrder() {
		return order;
	}

	public void setOrder(Integer order) {
		this.order = order;
	}

	public Boolean getEnable() {
		return enable;
	}

	public void setEnable(Boolean enable) {
		this.enable = enable;
	}

	public Map<String, List<String>> getRequestDecryptParamMap() {
		return requestDecryptParamMap;
	}

	public void setRequestDecryptParamMap(Map<String, List<String>> requestDecryptParamMap) {
		this.requestDecryptParamMap = requestDecryptParamMap;
	}

	public List<String> getRequestDecryptParams(String uri) {
		List<String> params = requestDecryptParamMap.get(uri);
		if (CollectionUtils.isEmpty(params)) {
			return new ArrayList<>();
		}
		return params;
	}

	public String getResponseCharset() {
		return responseCharset;
	}

	public void setResponseCharset(String responseCharset) {
		this.responseCharset = responseCharset;
	}
}
